
/**
 * 判断是支付宝app的浏览器
 */
const isAliPay = () => {
    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.match(/Alipay/i) == "alipay") {
        return true;
    } else {
        return false;
    }
}

/**
 * 判断是微信app的浏览器
 */
const isWeiXin = () => {
    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

/**
 * 格式化时间 默认 yyyy-MM-dd HH:mm:ss
 * @param {*} d 
 */
const formatDateTime = d => {
    if (d instanceof Date) {
        return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    }
    return '';
}

/**
 * 格式化时间 默认 yyyy-MM-dd
 * @param {*} d 
 */
const formatDate = d => {
    if (d instanceof Date) {
        return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
    }
    return '';
}

export {
    isAliPay,
    isWeiXin,
    formatDateTime,
    formatDate
}